#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "parse.h"

void parse_cmd(char *line, struct cmd *cmd)
{
    cmd->argc = 0;
    char *token = strtok(line, " \t\n");
    while (token != NULL) {
        if (cmd->argc < MAX_ARGC) {
            cmd->argv[cmd->argc] = token;
            cmd->argc++;
        } else {
            perror("Too many arguments");
            exit(EXIT_FAILURE);
        }
        token = strtok(NULL, " \t\n");
    }
    cmd->argv[cmd->argc] = NULL;
}

void dump_cmd(struct cmd *cmd)
{
    printf("argc = %d\n", cmd->argc);
    int i;
    for (i = 0; i < cmd->argc; i++) {
        printf("argv[%d] = (%s)\n", i, cmd->argv[i]);
    }

}
